package org.ignoramus.application.view.rcp;

import java.util.Iterator;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.ignoramus.application.model.Cards;
import org.ignoramus.application.model.ReviewCard;
import org.ignoramus.application.view.CardView;
import org.ignoramus.application.view.MemoryMap;

public class SwtMemoryMap extends MemoryMap
{
//	final Table table;

	private final Composite map;
	
	private static final int default_cols = 20;
	private static final int default_rows = 15;
	private final double ratioWidthOnHeight = (double)default_cols/(double)default_rows;
	
	/**
	 * @param parent 
	 * @param cards
	 */
	public SwtMemoryMap(Composite parent, Cards cards)
	{
		map = new Composite(parent, SWT.None);
//		table = new Table(parent, SWT.BORDER);
		Display display = parent.getDisplay();
		Color white = display.getSystemColor(SWT.COLOR_WHITE);
		map.setBackground(white);
		
		int maxChars = 1;
		
		for (Iterator<ReviewCard> iterator = cards.values().iterator(); iterator.hasNext();)
		{
			ReviewCard card = iterator.next();
			String title = card.getTitle();
	        if(title.length() > maxChars)
	        {
	        	maxChars = title.length();
	        }
		}
		int cols = (int) Math.ceil(Math.sqrt(ratioWidthOnHeight * ((double)1 / (double)maxChars) * cards.size()));
		map.setLayout(new GridLayout(cols, true));
//		for (int i = 0; i < cols; i++)
//		{
//			new TableColumn(table, SWT.NONE);
//		}
		
		super.init(cards);
	}

	/**
	 * @param card
	 */
	@Override
	protected void addCardView(CardView cardView)
	{
		// TODO Auto-generated method stub
		
	}

	/**
	 * @param card
	 * @return
	 */
	protected CardView createCardView(ReviewCard card)
	{
		return  null;
	}
}